package com.py;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;

public class CurlUtil {
    private static Logger logger = LoggerFactory.getLogger(CurlUtil.class);
    public static String execCurl(String[] cmds){
        Process p;
        try{
            p=Runtime.getRuntime().exec(cmds);
            logger.info(loadStream(p.getInputStream()));
            logger.info(loadStream(p.getErrorStream()));
        }
        catch (IOException e){
            logger.error("error!  "+e.toString());
        }
        return null;
    }

    public static String loadStream(InputStream in) throws IOException{
        int ptr=0;
        in = new BufferedInputStream(in);
        StringBuffer buffer = new StringBuffer();
        while((ptr=in.read())!=-1){
            buffer.append((char)ptr);
        }
        return buffer.toString();
    }
}
